package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component //交给IOC容器管理
//@Aspect //表示该类为切面类
@Slf4j //lombok工具包
public class TimeAspect {
    @Around("execution(* com.itheima.service.*.*(..))")//匹配方法
    public Object recordTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        //开始时间
        long begin = System.currentTimeMillis();
        //执行原始方法
        Object result = proceedingJoinPoint.proceed();
        //结束时间
        long end = System.currentTimeMillis();
        //输出原始方法执行时间
        log.info("Time taken: {} ms", end - begin);
        //返回原始方法返回值
        return result;
    }
}
